package com.wang.di.utils;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

public class CommonUtils {

    public static <T> T find(List<T> list, Predicate<T> predicate) {
        for (T t : list) {
            if (predicate.test(t)) return t;
        }
        return null;
    }

    public static <T> T find(T[] list, Predicate<T> predicate) {
        for (T t : list) {
            if (predicate.test(t)) return t;
        }
        return null;
    }

    public static <T, K> K findMap(T[] list, Map<T, K> map) {
        for (T t : list) {
            K obj = map.get(t);
            if (obj == null) continue;
            return obj;
        }
        return null;
    }

    public static <T, K> K findMap(List<T> list, Map<T, K> map) {
        for (T t : list) {
            K obj = map.get(t);
            if (obj == null) continue;
            return obj;
        }
        return null;
    }
}
